import { login } from "@/api/user";
import { UserInfo } from "@/types/user";
import { defineStore } from "pinia";

const useUserStore = defineStore('user', {
    state: () => {
        return {
            token: '',
            username: ''
        }
    },
    actions: {
        async userLogin(logInfo: UserInfo) {
            const result = await login(logInfo)
            if (result.code == 1 || result.code == 200) {
                localStorage.setItem('token', result.data)
                this.token = result.data
            }
        }
    }
})

export default useUserStore